<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="受检企业" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入受检企业"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="受检商品" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入受检商品"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信用代码" prop="uniformCode">
        <el-input
          v-model="queryParams.uniformCode"
          placeholder="请输入信用代码"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采样时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="采样类型" prop="sampleType">
        <el-select
          v-model="queryParams.sampleType"
          placeholder="请选择采样类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in sampleTypeSelect"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="检测方法" prop="checkMethod">
        <el-select
          v-model="queryParams.checkMethod"
          placeholder="请选择采样类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in checkMethodSelect"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="检测类型" prop="checkType">
        <el-select
          v-model="queryParams.checkType"
          placeholder="请选择采样类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in checkTypeSelect"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="检测结果" prop="result">
        <el-select
          v-model="queryParams.result"
          placeholder="请选择采样类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in resultList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <a @click="toggleAdvanced" style="margin-left: 8px">
          {{ advanced ? '收起' : '展开' }}
          <i v-if="!advanced" class="el-icon-arrow-down"></i>
          <i v-if="advanced" class="el-icon-arrow-up"></i>
        </a>
      </el-form-item>
    </el-form>


    <!--表格顶部操作栏-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['detection:enter:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格数据-->
    <el-table v-loading="loading" :data="checkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="采样编号" align="center" prop="sampleNo" :show-overflow-tooltip="true" width="200"/>
      <el-table-column label="受检企业" align="center" prop="companyName" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="受检企业信用代码" align="center" prop="uniformCode" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="受检商品" align="center" prop="goodsName" width="120" />
      <el-table-column label="检测项目" align="center" prop="itemName" :show-overflow-tooltip="true" width="240" />
      <el-table-column label="采样人" align="center" prop="sampler" width="120" />
      <el-table-column label="采样类型" align="center" prop="sampleType" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.sampleType === 'self' ">企业自检</span>
          <span v-if="scope.row.sampleType === 'task' ">任务检测</span>
          <span v-if="scope.row.sampleType === 'deliver' ">现场送检</span>
        </template>
      </el-table-column>
      <el-table-column label="采样时间" align="center" prop="sampleTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sampleTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采样机构" align="center" prop="sampleOrgName" width="150" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleDetail(scope.row)"
            v-hasPermi="['detection:enter:edit']"
          >详情</el-button>

        </template>
      </el-table-column>
    </el-table>

    <!-- 底部分页-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

import {listCheck} from "@/api/detection/check/check";

export default {
  name: "index",
  data() {
    return {
      advanced: false,
      showSearch: true,
      dateRange: [],
      loading: false,
      single: true,
      multiple: true,
      checkList: [],
      total: 0,
      queryParams: {
        sampleType: undefined,
        pageNum: 1,
        pageSize: 10
      },
      sampleTypeSelect: [
        {
          label: "企业自检",
          value: "self"
        },
        {
          label: "现场送检",
          value: "deliver"
        },
        {
          label: "任务检测",
          value: "task"
        }
      ],
      checkMethodSelect: [
        {
          label: "酶抑制法",
          value: 1,
        },
        {
          label: "分光光度计",
          value: 2,
        },
        {
          label: "化学比色法",
          value: 3,
        },
        {
          label: "胶体金免疫法",
          value: 4,
        }
      ],
      checkTypeSelect: [
        {
          label: "定性",
          value: 1,
        },
        {
          label: "定量",
          value: 2,
        }
      ],
      resultList: [
        {
          label: "阴性（合格）",
          value: 1
        },
        {
          label: "阳性（不合格）",
          value: 2
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(){
      listCheck(this.buildQueryTime(this.queryParams, this.dateRange)).then(res => {
        this.checkList = res.data;
        this.total = res.total;
      })
    },
    handleQuery(){
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    resetQuery(){
      this.queryParams = {
        pageNum: 1,
        pageSize: 10
      }
    },
    toggleAdvanced(){
      this.advanced = !this.advanced
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sampleId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleDetail(){

    },
    handleExport(){

    }
  }
}
</script>

<style scoped>

</style>
